export default {
	init: (Vue) => {
		/**
		 * 把 秒数时间戳格式化成字符串
		 * @param {Object} value
		 */
		Vue.prototype.get_datetime_by_chuo = function(value) {
			var date = new Date(value * 1000);
			var year = date.getFullYear(); //获取完整的年份(4位,1970-????)
			var month = date.getMonth() + 1; //获取当前月份(0-11,0代表1月)
			var day = date.getDate(); //获取当前日(1-31)
			var hours = date.getHours();
			var mi = date.getMinutes();
			var ss = date.getSeconds()
			if (mi < 10) {
				mi = "0" + mi;
			}
			if (month < 10) {
				month = "0" + month;
			}
			if (day < 10) {
				day = "0" + day;
			}
			if (hours < 10) {
				hours = "0" + hours;
			}
			var dateString = month + "-" + day + " " + hours + ":" + mi + ":" + ss;
			return dateString;
		}

		/**
		 * @param {Object} msg
		 * 弹出toast消息提示
		 */
		Vue.prototype.show_msg = function(msg) {
			uni.showToast({
				"title": msg,
				icon: "none",
				duration: 2000
			})
		}
		/**
		 * @param {Object} msg
		 * 弹出消息询问框，没有取消按钮，没有回调
		 */
		Vue.prototype.alert = function(msg) {
			uni.showModal({
				title: "提示",
				content: msg,
			})
		}


		Vue.prototype.query_el = function(that, id) {
			const query = uni.createSelectorQuery().in(that);
			query.select('#' + id).boundingClientRect(data => {
				console.log("得到布局位置信息" + JSON.stringify(data));
			}).exec();
		}

		Vue.prototype.base_modal_options = {
			confirm_text: "确定",
			confirm_text_color: "blue",
			show_cancel: true,
			cancel_text: "取消",
			cancel_text_color: "red",
			title:"提示",
			content:"",
			content_style:{}
		}
			
		Vue.prototype.shuffle = (arr) => {
			let i = arr.length;
			while (i) {
				let j = Math.floor(Math.random() * i--);
				[arr[j], arr[i]] = [arr[i], arr[j]];
			}
			return arr;
		}

	}
}
